package com.xxx.lib.base

/**
 * Activity二级基类
 */
abstract class BasePresenterActivity<V : IBaseView, P : BasePresenter<V>> : BaseActivity() {

    /**
     * P层
     */
    private var presenter: P? = null

    /**
     * 创建P层
     */
    protected abstract fun createPresenter(): P

    /**
     * 获取P层
     */
    protected fun getPresenter(): P {
        if (presenter == null) {
            presenter = createPresenter()
            if (this is IBaseView) presenter?.attachView(this as V)
        }
        return presenter as P
    }

    override fun onDestroy() {
        super.onDestroy()
        getPresenter().detachView()
    }
}
